package com.nd.android.u.ui.beanStarApp;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.text.SpannableString;
import android.widget.ImageView;

import com.common.android.utils.smiley.Smiley;
import com.nd.android.u.business.db.table.RecentContactRecordTable;
import com.nd.android.u.chatInterfaceImpl.ChatInterfaceImpl;
import com.nd.android.u.controller.ChatConst.KEY;
import com.nd.android.u.controller.bean.contact.ForwardingParam;
import com.nd.android.u.controller.bean.contact.RecentContactItem;
import com.nd.android.u.controller.innerInterface.IMessageDisplay;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.StarAppChatConst.MessageType;
import com.nd.android.u.ui.activity.message_chat.ChatActivity_Assistant;
import com.nd.android.u.ui.chatUiUtils.ChatCommonUtils;

/**
 * 消息助手
 * <br>Created 2014-9-10 下午5:39:41
 * @version  
 * @author   cb		
 * @see 	 
 */
public class AssistantContactItem extends RecentContactItem {


	@Override
	public int getMessageType() {
		return MessageType.ASSISTANT;
	}

	@Override
	protected void cursor2Identity(String identity) {
		mId = identity;
	}

	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if (o instanceof AssistantContactItem) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hashCode = getHashCodeHelper();
		hashCode = 31 * hashCode + subType;
		return hashCode;
	}

	@Override
	public void addIdentity(ContentValues values) {
		values.put(RecentContactRecordTable.COLUMN_EXTRA_ID, mId);
	}

	@Override
	public String getIdentity() {
		return mId;
	}

	@Override
	public SpannableString getContentText() {
		if (spannableText==null){
			spannableText=ChatCommonUtils.getSmileySpannableString(mLastMsgContent,Smiley.TYPE_CHAT, mLastMsgId);	
		}
	    return spannableText;
	}

	@Override
	public void onClickHeadPortrait(Context ctx) {
		onClickItem(ctx);
	}

	@Override
	public void onClickItem(Context ctx) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		bundle.putString(KEY.NAME, name);
		intent.putExtras(bundle);
		intent.setClass(ctx, ChatActivity_Assistant.class);
		ctx.startActivity(intent);
	}

	@Override
	public String getMsgTitle(Context ctx) {
		return ctx.getString(R.string.contact_assistant);
	}

	@Override
	public void displayHeadPortrait(ImageView iv) {
		ChatInterfaceImpl.INSTANCE.headerBitmapInterface.displayByApp(iv, 0, "");
	}

	@Override
	public void cursor2Item(Cursor cursor) {
		super.cursor2Item(cursor);
		subType = cursor.getInt(cursor
				.getColumnIndex(RecentContactRecordTable.COLUMN_SUB_TYPE));
	}

	@Override
	public ContentValues toContentValues() {
		ContentValues values = super.toContentValues();
		values.put(RecentContactRecordTable.COLUMN_SUB_TYPE, subType);
		return values;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder(super.toString());

		sb.append("mSubtype：");
		if (subType == 0) {
			sb.append("null");
		} else {
			sb.append(subType);
		}
		sb.append('，');

		return sb.toString();
	}

	@Override
	public void onForwarding(Activity activity, ForwardingParam forwardingParam) {
		//DO NOTHING
	}

	@Override
	public boolean isPrimaryKeyValid() {
		return true;
	}

	@Override
	protected IMessageDisplay getDisplayMessage() {
		return null;
	}
}
